package com.pfc.others;

import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.widget.Toast;
  
public class GPSManagement {  
  
    /*public static double latitude;  
    public static double longitude;  
  
  
    @Override  
    public void onLocationChanged(Location loc)  
    {  
        loc.getLatitude();  
        loc.getLongitude();  
        latitude=loc.getLatitude();  
        longitude=loc.getLongitude();  
    }  
  
    @Override  
    public void onProviderDisabled(String provider){  
    	System.out.println("Disabled provider " + provider);
    }  
    @Override  
    public void onProviderEnabled(String provider){  
    	System.out.println("Enabled new provider " + provider);
    }  
    @Override  
    public void onStatusChanged(String provider, int status, Bundle extras){  
    } */ 
	public void GPSManagement(){  
	}
    
    public double[] getCoordinates(Context context){
	     // Get the location manager
	     double[] coordinates = new double[2];
		 LocationManager locationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
		 Criteria criteria = new Criteria();
		 String bestProvider = locationManager.getBestProvider(criteria, false);
		 Location location = locationManager.getLastKnownLocation(bestProvider);
		 if (location!=null) {
	       coordinates[0] = location.getLongitude();	//-3
	       coordinates[1] = location.getLatitude();		//40
	     }
	     else{
	    	coordinates[0] = 0.0;
		    coordinates[1] = 0.0;	
	     	Toast.makeText(context,"GSP no disponible",Toast.LENGTH_LONG).show();
	     }
	     return coordinates;
   }
    
    public boolean areIqualCoordinates(double[] coord1, double[] coord2){
		double margin=0.001;
		if (Math.abs(coord1[0]-coord2[0])<margin && Math.abs(coord1[1]-coord2[1])<margin)
			return true;
		else return false;
	}
}  